package com.yneusoft.manage.controller;

import com.yneusoft.common.model.ResponseWrapper;
import com.yneusoft.manage.model.param.*;
import com.yneusoft.manage.service.DepartmentManageService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 部门管理控制层
 */
@RestController
@CrossOrigin
public class DepartmentManageController {
    @Resource
    DepartmentManageService departmentManager;

    /**
     * 启用/禁用部门
     * @param param 部门aid
     * @return true，false
     */
    @GetMapping("/departmentManage/isDepartment")
    public ResponseWrapper isDepartment(UpdateDepartmentStateParam param){
        return departmentManager.isDepartment(param);
    }

    /**
     * 获取部门状态列表
     * @return 状态list
     */
    @GetMapping("/departmentManage/getDepartmentState")
    public ResponseWrapper getDepartmentState(){
        return departmentManager.getDepartmentState();
    }

    /**
     * 【新增/修改】获取部门状态列表
     * @return 状态list
     */
    @GetMapping("/departmentManage/getDepartmentStateList")
    public ResponseWrapper getDepartmentStateList(){
        return departmentManager.getDepartmentStateList();
    }

    /**
     * 【新增/修改】获取修改部门列表
     * @param param 部门aid
     * @return 部门list
     */
    @GetMapping("/departmentManage/DepartmentInfo")
    public ResponseWrapper getDepartmentInfo(UpdateDepartmentListParam param){
        return departmentManager.getDepartmentInfo(param);
    }


    /**
     * 获取部门信息列表
     * @param param 部门aid
     * @return 排除当前部门的aid，name的list
     */
    @GetMapping("/departmentManage/getDepartmentNameList")
    public ResponseWrapper getDepartmentNameList(GetDepartmentNameListParam param){
        return departmentManager.getDepartmentNameList(param);
    }

    /**
     * 【新增/修改】校验同名的部门
     * @param param 校验同名的部门aid，name参数
     * @return true,false
     */
    @GetMapping("/departmentManage/checkDepartmentName")
    public ResponseWrapper checkDepartmentName(CheckDepartmentNameParam param) {
        return departmentManager.checkDepartmentName(param);
    }

    /**
     * 删除部门
     * @param param 部门aid
     * @return true，false(是否删除成功)
     */
    @PostMapping("/departmentManage/deleteDepartment")
    public ResponseWrapper deleteDepartment(@RequestBody DeleteDepartmentParam param) {
        return departmentManager.deleteDepartment(param);
    }


    /**
     * 验证父类是否为其子孙类分类
     * @param param aid(部门aid)，fatherAid(父部门aid)
     * @return true，false(是否是其子孙分类)
     */
    @GetMapping("/departmentManage/isChildren")
    public ResponseWrapper checkFatherDepartment(CheckFatherDepartmentParam param){
        return departmentManager.checkFatherDepartment(param);
    }


    /**
     * 部门列表展示
     * @param param searchKey(关键字,不必须)，id(状态id,不必须)，page(当前页,必须)，pageSize(页的条数,必须)
     * @return 部门的树结构列表
     */
    @GetMapping("/departmentManage/getDepartmentList")
    public ResponseWrapper test(DepartmentTreeParam param){
        return departmentManager.getDepartmentTree(param);
    }


    /**
     * 新增/修改部门信息保存
     * @param param 新增/修改部门信息参数实体类
     * @return 成功/失败
     */
    @PostMapping("/departmentManage/saveDepartment")
    public ResponseWrapper saveDepartment(@RequestBody @Validated SaveDepartmentParam param){
        return departmentManager.saveDepartment(param);

    }
}
